export default {
  // 开启命名空间
  namespaced:true,
  // 数据
  state: () => ({
    // 3. 读取本地的收货地址数据，初始化 address 对象
    address:JSON.parse(uni.getStorageSync('userAddress') || '{}'),
  }),
  // 方法
  mutations:{
    // 更新收获地址
    updateAddress (state,address) {
      state.address = address
      // 2. 通过 this.commit() 方法，调用 m_user 模块下的saveAddressToStorage 方法将 address 对象持久化存储到本地
      this.commit('user/saveAddressToStorage')
    },
    // 1. 定义将 address 持久化存储到本地 mutations 方法
    saveAddressToStorage (state) {
      uni.setStorageSync('userAddress',JSON.stringify(state.address))
    }
  },
  // 类似计算属性
  getters:{
    addressStr (state) {
      if(!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}